'use strict';
/**
 * 发送消息提醒给微信关注用户
 */
const Service = require('egg').Service;
const axios = require('axios');
const petregistModel = require('../../model/PetRegisterInfoModel');
const petregist = new petregistModel();
class wxchatService extends Service {

    async SendTemplate(openid, data) {
    // const appId = 'wx833268732e68920c';
    // this.appSecret = '92d5f8b18485998950486d25a41ca14c';
    const url = 'https://www.hbzner.com';
    const templateId = 'i0nUI5zbFQbNhSmU-4iZDiS11uaWM33LQ_H0FABlMNQ';
    const miniprogram = {
        appid: 'wx8a3e72751aa71401',
        // pagepath:"index?foo=bar"
    };
    const tokens = await petregist.wxquerytoken(this.app);
    console.log('数据库查到的access_token', tokens);
    const moban = await axios({
        method: 'POST',
        url: `https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=${tokens}`,
        data: {
            touser: openid,
            template_id: templateId,
            url,
            miniprogram,
            data: {
                    first: {
                        value: data.first,
                        color: '#173177',
                    },
                    keyword1: {
                        value: data.keyword1,
                        color: '#173177',
                    },
                    keyword2: {
                        value: data.keyword2,
                        color: '#173177',
                    },
                    keyword3: {
                        value: data.keyword3,
                        color: '#173177',
                    },
                    keyword4: {
                        value: data.keyword4,
                        color: '#173177',
                    },
                    remark: {
                        value: data.remark,
                        color: '#173177',
                    },
                },
        },
      });
      console.log('-------模板-------', moban);
    }
}
module.exports = wxchatService;
